import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/component/app_bar/index.dart';
import 'package:provider/provider.dart';

import 'dynamic_model.dart';
import 'first_page.dart';
// import 'first_page.dart';

class _DynamicAddSecond extends StatefulWidget {
  _DynamicAddSecond({Key? key}) : super(key: key);

  @override
  __DynamicAddSecondState createState() => __DynamicAddSecondState();
}

class __DynamicAddSecondState extends State<_DynamicAddSecond> {
  @override
  Widget build(BuildContext context) {
    final witchState = context.watch<DynamicModel>();
    final readState = context.read<DynamicModel>();
    return Scaffold(
        appBar: MyAppBar(
          title: 'ptovider Demo',
        ),
        body: Column(
          children: [
            ElevatedButton(
                onPressed: () {
                  readState.increment();
                  // context.rea  d<DynamicModel>().increment();
                },
                child: Text('修改count')),
            Text(

                /// Calls `context.watch` to make [Count] rebuild when [Counter] changes.
                '${witchState.count}',
                key: const Key('counterState'),
                style: Theme.of(context).textTheme.headline4)
          ],
        ));
  }
}

class ProviderDemoSecond extends StatelessWidget {
  ProviderDemoSecond({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider.value(
      value: DynamicModel.sharedDynamicModel,
      child: _DynamicAddSecond(),
    );
  }
}
